package main.java.com.demo;

import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.util.ArrayList;
import java.util.List;

public class App {
    public static void main(String[] args) {
//        Elements elements=JsoupTool.getElements("http://update.cs2c.com.cn:8080/NS/V10/V10SP1.1/os/adv/lic/updates/aarch64/repodata/", "td > a");
//        elements=filter(elements);
//        List<String>hrefs=JsoupTool.getHrefs(elements);
//        hrefs=filter(hrefs, "http://update.cs2c.com.cn:8080/NS/V10/V10SP1.1/os/adv/lic/updates/aarch64/repodata/");
//        DownloadTool.download("C:\\xxx\\repodata", hrefs);

        DownloadTool.downloadTxt("C:\\Users\\xxx\\Desktop\\" +
                        "我可以穿越进热血传奇游戏.txt"
                , "https://www.477zw.com/html/216/216256/", "https://www.477zw.com/"
                , "#list > dl > dd > a", "#content", 90);
    }

    public static Elements filter(Elements elements) {
        Elements list=new Elements();
        for(Element element: elements) {
            String text=element.text().trim();
            if (text.equals("Parent Directory")) {
                System.out.println("Parent Directory");
                continue;
            }
            list.add(element);
        }
        return list;
    }

    public static List<String> filter(List<String> hrefs, String prefix) {
        List<String> list=new ArrayList<>();
        for(String href: hrefs) {
            if(!href.startsWith(prefix)) {
                href=prefix+href;
            }
            list.add(href);
        }
        return list;
    }
}
